package com.zhou.datapick;

import com.zhou.util.StringTool;
import lombok.Data;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;

/**
 * @author lang.zhou
 * @since 2023/1/17 12:59
 */
@Data
public class DataKey {
    private static final long serialVersionUID = 1L;

    private String[] keys;

    public DataKey(String... keys) {
        this.keys = keys;
    }

    public static void main(String[] args) {
        HashSet<Object> set = new HashSet<>();
        set.add(new DataKey("1","2"));
        set.add(new DataKey("1"));
        set.add(new DataKey("1","2"));
        System.out.println();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DataKey dataKey = (DataKey) o;
        if(dataKey.keys.length != keys.length){
            return false;
        }
        for (int i = 0; i < keys.length; i++) {
            if(!Objects.equals(keys[i],dataKey.keys[i])){
                return false;
            }
        }
        return true;
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(keys);
    }

    @Override
    public String toString() {
        return keys == null ? "" : StringTool.join(keys,"_");
    }
}
